package com.sumainfor.pc.market.controller;

import com.sumainfor.common.entity.ParentDeptVo;
import com.sumainfor.common.entity.SysUserVo;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.service.MarketWorkbenchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/4/19 10:20
 * @Description:
 */
@RestController
@RequestMapping("/workbench")
public class MarketWorkbechController {

    @Autowired
    MarketWorkbenchService MarketWorkbenchService;

    /**
     * 功能描述:
     * 获取业主来源占比
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/14 17:56
     */
    @GetMapping("/CountSource")
    public JsonResult CountSource(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        result.put(MarketWorkbenchService.CountSource(params));
        return result;
    }

    /**
     * 功能描述:
     * 获取收房专员主页数据统计
     * 已通过盈利预测，已驳回盈利预测，审核中盈利预测，本月已收房，待联系业主
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/15 11:13
     */
    @GetMapping("/getHouseCount")
    public JsonResult getHouseCount(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"HouseId"})){
            result.putFailed("HouseId不能为空！");
            return  result;
        }
        result.put(MarketWorkbenchService.getHouseCount(params));
        return result;
    }

    /**
     * 功能描述:
     * 根据当前收房专员编号获取个人收房走向
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/15 14:07
     */
    @GetMapping("/getHouseInfoMap")
    public JsonResult getHouseInfoMap(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"HouseId"})){
            result.putFailed("HouseId不能为空！");
            return  result;
        }
        params.put("delfg",0);
        //业主待收录房源
        params.put("OwState",5);
        //房源收录成功
        params.put("ProState",7);
        result.put(MarketWorkbenchService.getHouseInfoMap(params));
        return result;
    }

    /**
     * 功能描述:
     * 获取租客来源占比
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/14 17:56
     */
    @GetMapping("/getTenantSourceCount")
    public JsonResult getTenantSourceCount(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        result.put(MarketWorkbenchService.getTenantSourceCount(params));
        return result;
    }

    /**
     * 功能描述:
     * 获取市场部经理的重要信息提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/11 20:52
     */
    @GetMapping("/getMatketManager")
    public JsonResult getMatketManager(){
        JsonResult result=new JsonResult();
        result.put(MarketWorkbenchService.getMatketManager());
        return result;
    }

    /**
     * 功能描述:
     * 获取市场部经理的房源信息
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/16 20:31
     */
    @GetMapping("/getMatketHousing")
    public JsonResult getMatketHousing(){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMatketHousing());
    }

    /**
     * 功能描述:
     * 市场部经理各中心成交额
     * 市场部经理各中心带看
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/17 15:14
     */
    @GetMapping("/getMatketTurnover")
    public JsonResult getMatketTurnover(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMatketTurnover(params));
    }

    /**
     * 功能描述:
     * 服务中心经理重要信息提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:27
     */
    @GetMapping("/getMarketSerMeassage")
    public JsonResult getMarketSerMeassage(){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSerMeassage());
    }

    /**
     * 功能描述:
     * 服务中心经理待审核定价
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:44
     */
    @GetMapping("/getMarketSerPricing")
    public JsonResult getMarketSerPricing(){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSerPricing());
    }

    /**
     * 功能描述:
     * 服务中心经理需定价房源
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 14:59
     */
    @GetMapping("getMarketSerNotPricing")
    public JsonResult getMarketSerNotPricing(){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSerNotPricing());
    }

    /**
     * zc 修改
     * 服务中心经理需定价房源
     * @author zhoucong
     * @data 2019/8/12
     * @Param
     * @return
     */
    @GetMapping("getMarketSerNotPricNum")
    public JsonResult getMarketSerNotPricNum(){
        JsonResult result = new JsonResult();
        Map<String,Object> params = new HashMap<>();
        //获取当前登录人的服务中心编号
        SysUserVo userVo = ContextUtils.getSysUser();
        ParentDeptVo vo = null;
        for (int i = 0; i < userVo.getLength(); i++) {
            ParentDeptVo vo1 = userVo.getParentDeptVo();
            if (vo1.getType().equals(3)) {
                vo = vo1;
                break;
            }
        }
        if (vo!=null){
            params.put("area_id",vo.getDeptId());//当前登录人的服务中心编号
            System.out.println("area_id:"+vo.getDeptId());
        }
        return result.put(MarketWorkbenchService.getMarketSerNotPricNum(params));
    }


    /**
     * 功能描述:
     * 服务中心经理中心房源情况
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 15:44
     */
    @GetMapping("/getMarketSerCenter")
    public JsonResult getMarketSerCenter(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"areaId"})){
            result.putFailed("areaId不能为空！");
            return  result;
        }
        return result.put(MarketWorkbenchService.getMarketSerCenter(params));
    }

    /**
     * 功能描述:
     * 本月中心成交排名
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/18 18:20
     */
    @GetMapping("/getMarketUserClinch")
    public JsonResult getMarketUserClinch(){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketUserClinch());
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的重要状态提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/19 10:22
     */
    @GetMapping("/getMarketSalesStatus")
    public JsonResult getMarketSalesStatus(@RequestParam Map<String,Object> params){
        params.put("UserId", ContextUtils.getUserId());
        return JsonResult.success(MarketWorkbenchService.getMarketSalesStatus(params));
    }
    
    /**
     * 功能描述: 
     * 获取租赁顾问的房源状态提醒
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/19 17:48
     */
    @GetMapping("/getMarketSalesHouStatus")
    public JsonResult getMarketSalesHouStatus(){
        JsonResult result=new JsonResult();

      Map<String,Object> params = new HashMap<>();
        //获取当前登录人的服务中心编号
        SysUserVo userVo = ContextUtils.getSysUser();
        ParentDeptVo vo = null;
        for (int i = 0; i < userVo.getLength(); i++) {
            ParentDeptVo vo1 = userVo.getParentDeptVo();
            if (vo1.getType().equals(3)) {
                vo = vo1;
                break;
            }
        }
        if (vo!=null){
            params.put("area_id",vo.getDeptId());//当前登录人的服务中心编号
            System.out.println("area_id:"+vo.getDeptId());
        }



        return result.put(MarketWorkbenchService.getMarketSalesHouStatus(params));
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的个人销售数据汇总
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/19 19:57
     */
    @GetMapping("/getMarketSalesSummary")
    public JsonResult getMarketSalesSummary(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSalesSummary(params));
    }

    /**
     * 功能描述:
     * 获取租赁顾问的本月成交排名
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/20 11:58
     */
    @GetMapping("/getMarketSalesHeart")
    public JsonResult getMarketSalesHeart(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSalesHeart(params));
    }

    /**
     * 功能描述: 
     * 获取租赁顾问的本月成交率
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/21 13:16
     */
    @GetMapping("/getMarketSalesClinchMonth")
    public JsonResult getMarketSalesClinchMonth(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSalesClinchMonth(params));
    }

    /**
     * 功能描述: 
     * 本月公司成交排名
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/22 11:05
     */
    @GetMapping("/getMarketSalesClinchCom")
    public JsonResult getMarketSalesClinchCom(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        return result.put(MarketWorkbenchService.getMarketSalesClinchCom(params));
    }

    /**
     * 功能描述:
     * 获取市场部经理工作台的续租和续租率
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/7/22 15:22
     */
    @GetMapping("/getRenewalPactCount")
    public JsonResult getRenewalPactCount(){
        return JsonResult.success(MarketWorkbenchService.getRenewalPactCount());
    }

}
